package cn.ccit.action;

import java.util.List;

import cn.ccit.base.BaseConstants;
import cn.ccit.entites.SystemRole;
import cn.ccit.iservers.ISystemRoleServers;
import cn.ccit.model.BaseModel;
import cn.ccit.servers.SystemRoleServers;
import cn.ccit.util.GsonUtil;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ModelDriven;

/**
 * 
 * ClassName: SystemRoleAction <br/> 
 * Function: 用户角色action. <br/> 
 * Reason: TODO ADD REASON(可选). <br/> 
 * date: 2016年11月5日 下午3:14:30 <br/> 
 * 
 * @author wanghao 
 * @version  1.0
 * @since JDK 1.6
 */
public class SystemRoleAction extends BaseAction implements ModelDriven<SystemRole>{
	private ISystemRoleServers sysRoleserver=new SystemRoleServers();
	private SystemRole sRole=new SystemRole();
	private static final long serialVersionUID = 1L;
	public String addSystemRole() {
		BaseModel<SystemRole> ba = new BaseModel<SystemRole>();
		if(sysRoleserver.addSystemRole(sRole)){
			ba.setMessage(BaseConstants.SUCESSFUL_STATE_MESSAGE);
			ba.setStatus(BaseConstants.SUCESSFUL_STATE_CODE);
		}else{
			ba.setMessage(BaseConstants.FAIL_STATE_MESSAGE);
			ba.setStatus(BaseConstants.FAIL_STATE_CODE);
		}
		GsonUtil.sendJson(ba);
		return Action.SUCCESS;
	}
	
	
	public String removeSystemRole() {
		BaseModel<SystemRole> ba = new BaseModel<SystemRole>();
		if(sysRoleserver.removeSystemRole(sRole)){
			ba.setMessage(BaseConstants.SUCESSFUL_STATE_MESSAGE);
			ba.setStatus(BaseConstants.SUCESSFUL_STATE_CODE);
		}else{
			ba.setMessage(BaseConstants.FAIL_STATE_MESSAGE);
			ba.setStatus(BaseConstants.FAIL_STATE_CODE);
		}
		GsonUtil.sendJson(ba);
		return Action.SUCCESS;
	}
	public String changeSystemRoleInfo() {
		BaseModel<SystemRole> ba = new BaseModel<SystemRole>();
		if(sysRoleserver.changeSystemRoleInfo(sRole)){
			ba.setMessage(BaseConstants.SUCESSFUL_STATE_MESSAGE);
			ba.setStatus(BaseConstants.SUCESSFUL_STATE_CODE);
		}else{
			ba.setMessage(BaseConstants.FAIL_STATE_MESSAGE);
			ba.setStatus(BaseConstants.FAIL_STATE_CODE);
		}
		GsonUtil.sendJson(ba);
		return Action.SUCCESS;
	}
	public String getSomeSystemRoles() {
		BaseModel<List<SystemRole>> ba = new BaseModel<List<SystemRole>>();
		if(sysRoleserver.getSomeSystemRoles(startId,limit)!=null){
			ba.setMessage(BaseConstants.SUCESSFUL_STATE_MESSAGE);
			ba.setStatus(BaseConstants.SUCESSFUL_STATE_CODE);
			ba.setData(sysRoleserver.getSomeSystemRoles(startId,limit));
		}else{
			ba.setMessage(BaseConstants.FAIL_STATE_MESSAGE);
			ba.setStatus(BaseConstants.FAIL_STATE_CODE);
		}
		GsonUtil.sendJson(ba);
		return Action.SUCCESS;
	}
	public String searchSystemRoleByID() {
		BaseModel<SystemRole> ba = new BaseModel<SystemRole>();
		if(sysRoleserver.searchSystemRoleByID(sRole.getId())!=null){
			ba.setMessage(BaseConstants.SUCESSFUL_STATE_MESSAGE);
			ba.setStatus(BaseConstants.SUCESSFUL_STATE_CODE);
			ba.setData(sysRoleserver.searchSystemRoleByID(sRole.getId()));
		}else{
			ba.setMessage(BaseConstants.FAIL_STATE_MESSAGE);
			ba.setStatus(BaseConstants.FAIL_STATE_CODE);
		}
		GsonUtil.sendJson(ba);
		return Action.SUCCESS;
	}
	@Override
	public SystemRole getModel() {
		return sRole;
	}
	
	

}
